package org.juggers.remote;

import java.util.List;

import org.juggers.domain.InvalidCaptchaException;
import org.juggers.domain.JugEvent;
import org.juggers.domain.Jugger;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
import com.google.gwt.user.client.rpc.ServiceDefTarget;

/**
 * Juggers remote calendar service
 * 
 * @author michel@breizhjug.org
 */
@RemoteServiceRelativePath( "service.rpc" )
public interface JuggersService
    extends RemoteService
{

    /**
     * List upcoming events
     * 
     * @return Events
     */
    List<JugEvent> getEvents();

    /**
     * List event participants
     * 
     * @return Participants
     */
    List<Jugger> getParticipants( String eventId );

    /**
     * Subscribe to an event
     */
    void subscribe( String id, String captchaChallenge, String captchaResponse, Jugger jugger ) throws InvalidCaptchaException;

    public static class Util
    {
        private static JuggersServiceAsync instance = null;

        public static JuggersServiceAsync getInstance()
        {
            if ( instance == null )
            {
                instance = (JuggersServiceAsync) GWT.create( JuggersService.class );
                ( (ServiceDefTarget) instance ).setServiceEntryPoint( "/calendarService" );
            }
            return instance;
        }
    }
}
